/*
 * @Description: 
 * @Author: mmzhang
 * @Date: 2021-12-10 16:52:09
 * @LastEditTime: 2022-06-22 10:23:31
 */
import businessCommonMgr from '@/biz/businessReport/businessCommon'
import houseOpt from '@/biz/option/house.js'
import ruleOpt from '@/biz/option/rule.js'

import Opt from '@/components/dt/info/Opt.js'
import tool from '@/common/tool.js'
let _this = null
let companys = []
class SearchOpt extends Opt {

  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  getCompany() {
    let opt = {
      title: '组织筛选',
      key: 'companyIds',
      placeholder: '全部',
      tree: {
        options: companys,
        saveAll: true
      }
    }
    let params = {
      isTwoLevel: true,
    }
    businessCommonMgr
      .getOrgThreeTree(params)
      .then((res) => {
        companys = res
        opt.tree.options = companys
      })
    return opt
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }


  createAll() {
    this.all = [
      this.getCompany(),
      houseOpt.create({
        title: '推送案场',
        placeholder: '请输入推送案场',
        to: (info) => {
          return {
            buildingId: info.housesId
          }
        }
      }),

      {
        title: '主叫拨打时间',
        key: 'checkTime',
        placeholder: '请选择时间范围',
        xl: 4,
        date: {
          type: 'daterange',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          }
        },
        rules: [
          ruleOpt.check('日期跨度至多两年', (value) => {
            return value.length && tool.dateDiff(value[0], value[1]).Y >= 2
          })
        ]
      },

    ]
  }
}

export default SearchOpt